// Place your name class time and date here #include #include using std::cin; using std::cout; using std::endl; using std::ios_base; //order - efficiency //n^2, log n, n void Sort(double A[], int length) { for(int i =0; i <= length - 1; i++) { int indexOfEndOfUnsortedPartOfList = length - 1 - i; int indexOfLargest = 0; //find the real index of the largest in the range 0 through length -1 - i for(int j = 1; j <= indexOfEndOfUnsortedPartOfList; j++) { if(A[j] > A[indexOfLargest]) { indexOfLargest = j; } } //swap the item at the index indexOfLargest with the "end" item int temp = A[indexOfEndOfUnsortedPartOfList]; A[indexOfEndOfUnsortedPartOfList] = A[indexOfLargest]; A[indexOfLargest] = temp; } } void main() { //while(true) //{ // cout << time(NULL) << endl; //} srand(time(NULL)); const int GRADE_COUNT = 100; //arrays have contiguous memory allocation double grades[GRADE_COUNT]; //0-99 for(int i =0; i < GRADE_COUNT; i++) { //cin >> grades[i]; grades[i] = rand() % 100 + 1; } //sort them Sort(grades,GRADE_COUNT); for(int i =0; i < GRADE_COUNT; i++) { cout << grades[i] << endl; } }